function loadXMLDoc()
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var json = JSON.parse(xmlhttp.responseText);
            console.log(json);
            for (var i = 0; i<json.data.length; i++){
                var li = document.createElement("li");
                var sapn = document.createElement("span");
                var sap = document.createElement("span");
                var sa = document.createElement("span");
                sapn.innerHTML = json.data[i].studentName;
                sap.innerHTML = json.data[i].sex;
                sa.innerHTML = json.data[i].age;

                li.appendChild(sapn);
                li.appendChild(sap);
                li.appendChild(sa);

                document.querySelector('.ao').appendChild(li);
            }
        }
    };
    xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/student",true);
    xmlhttp.send();
}
loadXMLDoc()


document.querySelector("#btn").addEventListener('click',function(){
    var a = document.querySelector("#a").value;
    var b = document.querySelector("#b").value;
    var d = document.querySelector("#d").value;

    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            loadXMLDoc()
            document.querySelector(".ao").innerHTML="";
        }
    }
    xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/addStudent?studentName="+a+"&sex="+b+"&age=" + d,true);
    xmlhttp.send();
});

